import "./active.scss";
import $ from "jquery";
import Cart from "../../parts/cart/cart";
import ProfileMgr from "../../data/ProfileMgr";
import Header from "../../parts/inc/header.js";

let timer = null;
$(function(){
    // 开始倒计时
    startTime();
    // 购物车
    ProfileMgr.repeatLoad();
    $('.web_head').load('./header.html',function(){
        new Header();
        new Cart();
    });
    $('.footer').load('./footer.html');
    bindEvent();
});
// 点击活动规则
function bindEvent(){
    $(".activityImg").click(function(){
        $(this).siblings().css("display", "block");
    });
    $(".activityBj").click(function(){
        $(this).css("display","none")
        .siblings(".activityWarp")
        .css("display","none");
    });
    $(".activityWarp span").click(function(){
        $(this).parent()
        .css("display","none")
        .siblings(".activityBj")
        .css("display","none");
    });
}
// 倒计时
function countDown(time){
    var d       = parseInt(time / 3600 / 24);
    var h       = parseInt(time / 3600 % 24);
    var m       = parseInt(time / 60 % 60);
    var s       = time % 60;

    h           = h < 10 ? "0" + h : h;
    m           = m < 10 ? "0" + m : m;
    s           = s < 10 ? "0" + s : s;
    $(".day").html(d);
    $(".hour").html(h);
    $(".minute").html(m);
    $(".second").html(s);
}
function disposeCount(total){
    total       = parseInt(total / 1000);
    timer       = setInterval(()=>{
        total --;
        countDown(total);
        if(total <= 0){
            clearInterval(timer);
            startTime();
        }
    }, 1000);
}
function startTime(){
    let offTime = new Date(2019,7,1).getTime() - Date.now();
    disposeCount(offTime);
}